To create an event in a class, copy/paste these parts of code in the Properties/Methods part of your class, somewhere in the code of your class and as the EventArgs class (implement it further).
Replace <MyEvent> by a proper name.
(When this doesn't make any sense to you, read the Events tutorial in the MSDN Help.)
/// <summary> /// Event fired when ... /// </summary> public event <MyEvent>EventHandler <MyEvent>; /// <summary> /// Occurs when ... /// </summary> public delegate void <MyEvent>EventHandler(object sender, <MyEvent>EventArgs e); /// <summary> /// Raises the <see cref="<MyEvent>"/> event. /// </summary> /// <param name="e"></param> protected virtual void On<MyEvent>(<MyEvent>EventArgs e) { if (<MyEvent> != null) <MyEvent>(this,e); } |
// Create a <MyEvent> event <MyEvent>EventArgs arg = new <MyEvent>EventArgs(<MyData>); On<MyEvent>(arg); |
/// <summary> /// Overrides <see cref="System.EventArgs"/>. /// </summary> /// <remarks> /// Used in <see cref="?"/>. /// </remarks> public class <MyEvent>EventArgs : EventArgs { /// <summary> /// Constructor. /// </summary> public <MyEvent>EventArgs(<MyData>) { } } |